package com.sky.chapter1.daemon;

/**
 * @author : wushikai
 * <p>
 * date : 2021-03-25
 * 演示守护线程......
 */
public class DaemonThreadDemo {


    public static void main(String[] args) {


        Thread daemon = new Thread(() -> {
            int i = 0;
            while (true) {
                try {

                    Thread.sleep(1010);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                i++;
                if (i == 10) {
                    break;
                }
                System.out.println(Thread.currentThread().getName() + " 执行.... ");
            }

        }, "守望先锋");

        daemon.setDaemon(false); //设置位守护线程
        daemon.start();
        System.out.println(" 主线程已经结束, 但是程序依旧执行 ");

    }


}
